import { get, post } from './http'

export const SPACE = {
  // Space
  user: 'user',
  userCity: 'user-city',
  userRole: 'user-role',
  role: 'role',
  menu: 'menu',
  menuRole: 'menu-role',
  order: 'order',
  orderItem: 'order-item',
  item: 'item',
  itemImage: 'item-image',
  itemRecommend: 'item-recommend',
  itemType: 'item-type',
  city: 'city',
  cart: 'cart'
}

/** 增加 (insert开头) **/
export const insert = (space, data) => post(`${space}/insert`, data)

/** 删除 (delete开头) **/
export const deleteByIds = (space, ids) => post(`/${space}/delete`, ids)

/** 修改 (update开头) **/
export const update = (space, data) => post(`/${space}/update`, data)

/** 查询 (select开头) **/
// 通过id查找数据
export const selectById = (space, id) => get(`/${space}/selectById/${id}`)

// 查找表中数据条数(无条件)
export const selectCount = (space) => get(`/${space}/selectCount`)

// 查找表中数据条数(有条件)
export const selectCountByWord = (space, word) => get(`/${space}/selectCount/${word}`)

// 查找所有数据列表(无条件)
export const selectList = (space) => get(`/${space}/selectList`)

// 查找所有数据列表(外键id) 如: userId,typeId等
export const selectListByForeignId = (space, foreignId) => get(`/${space}/selectList/${foreignId}`)

// 查找所有数据列表(有条件)
export const selectListByWord = (space, word) => get(`/${space}/selectListByWord/${word}`)

// 分页查找数据集合(无条件)
export const selectPage = (space, current, size) => get(`/${space}/selectPage/${current}/${size}`)

// 查找所有数据列表(外键id)
export const selectPageByForeignId = (space, current, size, foreignId) => get(`/${space}/selectPage/${current}/${size}/${foreignId}`)

// 分页查找数据集合(有条件)
export const selectPageByWord = (space, current, size, word) => get(`/${space}/selectPageByWord/${current}/${size}/${word}`)
